<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
	<form action="" method="post">
			<input type="button" id="" value="确定" onclick="calculate()" />
		</form>
		<script type="text/javascript">
			function calculate(){
				var inputnum=prompt("请输入考试科目数量","");
				if(!isNaN(inputnum)&&inputnum.length>0){
					var sum=0;
					var flag=true;
					for(var i=1;i<=inputnum;i++){
						var inputpoint=prompt("请输入第"+i+"门课成绩");
						var point=parseFloat(inputpoint);
						if(!isNaN(inputpoint)&&point>=0){
							sum=sum+point;
						}else{
							alert("输入的不是数字");
							flag=false;
							break;
						}
					}
						if(flag==true){
							alert(inputnum+"门课总成绩是"+sum+"分");
						}
					
				}else{
					alert("输入的不是数字");
				}
			}
		</script>
	</body>
</html>
